package qtdz5;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public abstract class SeaObject {
    private static final int LIVE = 0;
    private static final int DEAD = 1;
    int state = LIVE;

    int height;
    int width;
    int x;
    int y;
    int speed;

    SeaObject(int width, int height) {
        this.height = height;
        this.width = width;
        x = -width;
        Random rand = new Random();
        y = rand.nextInt(479 + 1 - 150 - height) + 150;
        speed = rand.nextInt(3) + 1;
    }

    SeaObject(int width, int height, int x, int y, int speed) {
        this.height = height;
        this.width = width;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public abstract void move();

    public abstract ImageIcon getImage();

    public boolean isLive() {
        return state == LIVE;
    }

    public boolean isDead() {
        return state == DEAD;
    }

    public void paintImage(Graphics g) {
        if (this.isLive()) {
            this.getImage().paintIcon(null, g, this.x, this.y);
        }
    }
}
